-----------------------------------
-- Area: Metalworks
-- NPC: Iron Eater
-- Type: Quest/Mission NPC
-- Quests: The Weight of Your
-- Limits, Fires of Discontent, The
-- Doorman, Waking the Colossus
-- Missions: (Bastok) 2-2, 3-1,
-- 5-1, 6-1, 8-1, 8-2, 9-1, 9-2
-- @zone 237
-- @pos 92.936 -19.532 1.814
-----------------------------------
package.loaded["scripts/zones/Metalworks/TextIDs"] = nil;
-----------------------------------

require("scripts/globals/missions");
require("scripts/zones/Metalworks/TextIDs");

-----------------------------------
-- onTrade Action
-----------------------------------

function onTrade(player,npc,trade)
end;

-----------------------------------
-- onTrigger Action
-----------------------------------

function onTrigger(player,npc)

	local currentMission = player:getCurrentMission(BASTOK);
	local missionStatus = player:getVar("MissionStatus");

	if(currentMission == THE_FOUR_MUSKETEERS and missionStatus == 0) then -- Four Musketeers
		player:startEvent(0x02cb);
	elseif(currentMission == THE_FOUR_MUSKETEERS and missionStatus == 1) then
		player:startEvent(0x02cc);
	elseif(currentMission == THE_CHAINS_THAT_BIND_US and missionStatus == 0) then
	    player:startEvent(0x02ff); -- First cutscene of mission
	elseif (currentMission == THE_CHAINS_THAT_BIND_US) and (missionStatus == 2) then
		player:showText(npc, 8596); -- Dialogue after first cutscene
	elseif (currentMission == THE_CHAINS_THAT_BIND_US) and (missionStatus == 3) then
		player:startEvent(0x0300); -- Cutscene on return from Quicksand Caves
	elseif (currentMission == ENTER_THE_TALEKEEPER) and (missionStatus == 2) then
		player:startEvent(0x0301); -- Cutscene optional for Bastok 8-2
	elseif(player:getQuestStatus(CRYSTAL_WAR,FIRES_OF_DISCONTENT) == QUEST_ACCEPTED and player:getVar("fires") == 2)then
		player:startEvent(0x03BC);
	elseif(player:getQuestStatus(CRYSTAL_WAR,FIRES_OF_DISCONTENT) == QUEST_ACCEPTED and player:getVar("fires") == 3)then
		player:startEvent(0x03BD);
	else
		player:startEvent(0x025c);
	end

end;

-----------------------------------
-- onEventUpdate
-----------------------------------

function onEventUpdate(player,csid,option)
--printf("CSID: %u",csid);
--printf("RESULT: %u",option);
end;

-----------------------------------
-- onEventFinish
-----------------------------------

function onEventFinish(player,csid,option)
--printf("CSID: %u",csid);
--printf("RESULT: %u",option);
	if(csid == 0x02cb and option == 0) then
		player:setVar("MissionStatus",1);
	elseif(csid == 0x03bc)then
		player:setVar("fires",3);
	elseif(csid == 0x02ff and option == 0) then
	    player:setVar("MissionStatus", 1);
	elseif(csid == 0x0300) then
		finishMissionTimeline(player, 1, csid, option);
	end
end;